{extend name="layout/base"}
{block name='content'}
<body>
<div class="layui-fluid">
    <div class="layui-form">
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">文章标题：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="name" placeholder="请输入文章标题" lay-verify="required">
                </div>
            </div>
        </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submit">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    layui.use(['jquery', 'form', 'layer'], function ($, form, layer) {
        form.on('submit(submit)', function (obj) {
            $.ajax({
                type: 'post',
                url: "{:url('news/add')}",
                data: obj.field,
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 6});
                        parent.location.reload();
                    } else {
                        layer.msg(data.msg, {icon: 5});
                    }
                },
                error: function () {
                    layer.msg('请求错误', {icon: 5});
                }
            })
        });
    });
</script>
{/block}